package com.example.demo.model;

import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 22652
 * Date: 2024-07-10
 * Time: 17:08
 */

@Mapper
public interface UserInfoMapper_2 {

    @Select("select id, username, `password`, age, gender, phone, delete_flag, " +
            "create_time, update_time from userinfo")
    public List<UserInfo> selectAll();

    /*
     * 结果映射
     * 方法一: 对字段进行重命名
     * @return
     */
    @Select("select id, username, password, age, gender, phone," +
            " delete_flag as deleteFlag, create_time as createTime, update_time as updateTime" +
            " from userinfo")
    public List<UserInfo> selectAll_1();

    /*
     * 结果映射
     * 方法二: 使用注解
     * @return
     */
    @Results(id = "BaseMap",value = {
            @Result(column = "delete_flag",property = "deleteFlag"),
            @Result(column = "create_time",property = "createTime"),
            @Result(column = "update_time",property = "updateTime")
    })
    @Select("select * from userinfo")
    List<UserInfo> selectAll_2();

    //通过id来复用，Results
    @ResultMap(value = "BaseMap")
    @Select("select * from userinfo where id= '${id}'")
    UserInfo selectOne(Integer id);

    /*
     * 结果映射
     * 方法三: 使用配置的方式, 自动转驼峰
     * @return
     * 驼峰命名规则： abc_xyz => abcXyz
        • 表中字段名：abc_xyz
        • 类中属性名：abcXyz
     */
    @Select("select * from userinfo")
    List<UserInfo> selectAll_3();
}
